<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
	</head>
	<body>
		<div id="app">
			<div class="header">
				<span>修改快递信息</span>
			</div>
			<div class="content">
				<table>	
					<tr>
						<td class="text-right">运单号</td><td class="content_right"><input id="number-by" class="input inline-input" placeholder="请输入运单号码"> <span id="find" class="btn btn-info">立即查找</span></td>
					</tr>
				</table>
			</div>
			
			
			<div class="header">
				<span>查找信息如下</span>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="text-right">快递单号</td><td class="content_right"><input id="number" class="input" placeholder="请输入单号"></td>
					</tr>
					<tr>
						<td class="text-right">快递公司</td><td class="content_right"><input id="company" class="input" placeholder="请输入公司"></td>
					</tr>
					<tr>
						<td class="text-right">收货人姓名</td><td class="content_right"><input id="receiveName" class="input" placeholder="请输入姓名"></td>
					</tr>
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input id="receivePhone" class="input" placeholder="请输入手机号码"></td>
					</tr>
					<tr>
						<td class="text-right">快递状态</td><td class="content_right"><input type="radio" id="yes" class="status" name="status" value="1">已签收  <input name="status" id="no" class="status" type="radio" value="0">未签收</td>
					</tr>
					<tr>
						<td></td><td class="content_right"><span id="update" class="btn btn-info">立即修改</span> <span class="btn">重置</span> </td>
					</tr>
				</table>
			</div>
		</div>
	</body>
	<script src="../../qrcode/jquery2.1.4.js"></script>
	<script src="../../assets/layui.all.js"></script>

	<script>
		$(".header:eq(1),.content:eq(1)").hide();
		var id = null;
		var phone = null;
		$(function () {
			$("#find").click(function () {
				$(".header:eq(1),.content:eq(1)").hide();
				var number_by = $("#number-by").val()
				if(number_by==='' || number_by==null){
					layer.msg("单号不能为空！")
					return false;
				}
				var windowId = layer.load()
				$.post("/express/findByNumber.do",{number:number_by},function (data) {
					layer.close(windowId)
					layer.msg(data.result)
					if(data.status===1){
						id = data.data.id;
						phone = data.data.receivePhone;
						$("#company").val(data.data.company)
						$("#number").val(data.data.number)
						$("#receivePhone").val(data.data.receivePhone)
						$("#receiveName").val(data.data.receiveName)
						if(data.data.status===1){
							$("#yes").prop("checked",true);
						} else {
							$("#no").prop("checked",true);
						}
						$(".header:eq(1),.content:eq(1)").fadeIn(1000);
					}
				})
			})
			$("#update").click(function () {
				var number = $("#number").val()
				var company = $("#company").val()
				var receivePhone = $("#receivePhone").val()
				var receiveName = $("#receiveName").val()
				var status = $("input[name='status']:checked").val();
				if(number===null || number==='') {
					layer.msg("单号不能为空");
				} else if(receiveName===null || receiveName===''){
					layer.msg("收件人不能为空");
				}else if(company===null || company==='') {
					layer.msg("公司不能为空");
				} else if(!/^((0\d{2,3}-\d{7,8})|(1[345789]\d{9}))$/.test(receivePhone)) {
					layer.msg("手机号不符合规范");
				} else {
					var windowId = layer.load();
					var express = {
						id: id,
						number: number,
						company: company,
						receiveName: receiveName,
						status: status
					};
					if (receivePhone !== phone) {
						express.receivePhone = receivePhone;
					}
					$.post("/express/update.do", express, function (data) {
						layer.close(windowId);
						layer.msg(data.result)
						if (data.status === 0) {
							//修改成功
							$(".header:eq(1),.content:eq(1)").hide();
							id = null;
							phone = null;
							$("#company").val("顺丰快递")
							$("#number").val("")
							$("#receivePhone").val("")
							$("#receiveName").val("")
						}
					})
				}
			})

		})
	</script>
</html>
